﻿using Dashboard.Hubs;
using Dashboard.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MoaDashboard.Controllers
{
	public class HealthController : Controller
	{
		// GET: /Health/
		public ActionResult Index()
		{
			var full = HealthMonitor.FullHistory;
			var averaged = HealthMonitor.BySeconds();

			var result = new HealthView()
			{
				CpuUsage = full.Select(x => new DateTimeDoubleValue(x.Item1, x.Item2.CpuUsage)).ToList(),
				CpuUsageAveraged = averaged.Select(x => new DateTimeDoubleValue(x.Item1, x.Item2.CpuUsage)).ToList(),
				DiskUsage = full.Select(x => new DateTimeDoubleValue(x.Item1, x.Item2.DiskUsage)).ToList(),
				DiskUsageAveraged = averaged.Select(x => new DateTimeDoubleValue(x.Item1, x.Item2.DiskUsage)).ToList(),
				RamUsage = full.Select(x => new DateTimeDoubleValue(x.Item1, x.Item2.UsedRam)).ToList(),
				RamTotal = averaged.Select(x => new DateTimeDoubleValue(x.Item1, 100 * x.Item2.UsedRam / x.Item2.TotalRam)).ToList(),
			};

			return View(result);
		}
	}
}